<?php
namespace app\common\command;

use app\index\controller\Index;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;


class Task extends Command
{
    protected function configure()
    {
        //设置名称为task
        $this->setName('task')
            //增加一个命令参数
            ->addArgument('action', Argument::OPTIONAL, "action")
            ->addArgument('force', Argument::OPTIONAL, "force");
    }

    protected function execute(Input $input, Output $output)
    {
        //获取输入参数
        $action = trim($input->getArgument('action'));
        $force = trim($input->getArgument('force'));

        // 配置任务
        $task = new \EasyTask\Task();
        $task->setRunTimePath('./runtime/');
        $task->setDaemon(true);
        $task->addFunc(function () {

            //测试代码,运行前先把代码前//删除
            //file_put_contents("logs.txt","运行成功");
           //测试代码运行时需要把下放定时代码先注释了


            $hour = date('H');
            $time=date("i");
            $s=date("s");

            //每天早上9.30推送一次
            if ($hour=="09"&&$time=="30"&&$s=="00"){
                $index=new Index();
                $index->send();
            }else{
                return;
            }



        }, 'wxSend', 1, 1);

        // 根据命令执行
        if ($action == 'start')
        {
            $task->start();
        }
        elseif ($action == 'status')
        {
            $task->status();
        }
        elseif ($action == 'stop')
        {
            $force = ($force == 'force'); //是否强制停止
            $task->stop($force);
        }
        else
        {
            exit('Command is not exist');
        }
    }
}
